<?php

namespace app\comapi\controller\core;

use app\common\controller\Frontend;
use app\common\enums\core\PayTypeEnum;
use app\common\service\core\TrialClassOrderService;
use app\common\service\pay\AlipayService;
use app\common\service\pay\WxPayService;
use app\common\service\student\AccountClassHourService;

/**
 * 配置
 */
class CoreAccountClassHour extends Frontend
{
    protected array $noNeedLogin = ['*'];

    protected array $noNeedPermission = ['*'];

    public function initialize(): void
    {
        parent::initialize();
    }

    public function payCallWechat()
    {
        $wxPayService = new WxPayService();
        $res = $wxPayService->payNotify(function ($result) {
            $accountClassHourService = new AccountClassHourService();
            return $accountClassHourService->payCall($result['out_trade_no'], $result['total_price'], $result['transaction_id'], PayTypeEnum::WECHAT);
        });
        if ($res) {
            return json(['code' => "200"]);
        } else {
            return json(['code' => "FAIL", 'msg' => '支付失败']);
        }


    }

    public function payCallAlipay()
    {
        $alipayService = new AlipayService();
        $res = $alipayService->payNotify(function ($result) {
            $accountClassHourService = new AccountClassHourService();
            return $accountClassHourService->payCall($result['out_trade_no'], $result['total_price'], $result['transaction_id'], PayTypeEnum::ALIPAY);
        });
        if ($res) {
            return json(['code' => "success", 'msg' => '支付成功']);
        } else {
            return json(['code' => "fail", 'msg' => '支付失败']);
        }
    }


}